import { type UserDeviceLogsSearch } from "@/components/UserDeviceLogs/avue-options";
import { type DeviceLogModel } from "@/model/device-log-model";
import { type DeviceModel } from "@/model/device-model";
import { type UserDeviceModel } from "@/model/user-device-model";
import { type PageDataModel } from "@/model/page-data-model";
import { type PageParamsModel } from "@/model/page-params-model";
import request from "@/utils/request";
import { type DeviceSituationSearch } from "@/views/device/situation/avue-options";
import { type UserHouseDeviceLogsSearch } from "@/components/UserHouseDeviceLogs/avue-options";

const DeviceAPI = {
  /**
   * 获取设备分页列表
   *
   * @param queryParams 查询参数
   */
  getPage(data: any) {
    return request<any, PageDataModel<DeviceModel[]>>({
      url: "/admin/user/deviceList",
      method: "get",
      data,
    });
  },

  /**
   * @description 设备类型选项
   */
  getTypeOptions() {
    return request<any, any>({
      url: "/admin/user/deviceCategorySelectList",
      method: "get",
    });
  },

  /**
   * @description 添加
   * @param data
   * @returns
   */
  add(data: any) {
    return request<any, any>({
      url: "/admin/user/addDevice",
      method: "post",
      data,
    });
  },

  /**
   * @description 编辑
   * @param data 设备信息
   */
  edit(data: any) {
    return request<any, any>({
      url: "/admin/user/editDevice",
      method: "post",
      data,
    });
  },

  /**
   * @description 详情
   * @param id ID
   */
  detail(id: number | string) {
    return request<any, any>({
      url: "/admin/user/deviceDetail",
      method: "post",
      data: {
        id: id,
      },
    });
  },

  /**
   * @description 删除
   * @param id ID
   */
  delete(id: number | string) {
    return request<any, any>({
      url: "/admin/user/delDevice",
      method: "post",
      data: {
        id: id,
      },
    });
  },

  /**
   * @description 查询未绑定设备
   * @param {PageParamsModel} data
   */
  userWithDeviceUnbind(data: PageParamsModel) {
    return request<any, any>({
      url: "/admin/user/noBindUserDevice",
      method: "post",
      data: data,
    });
  },

  /**
   * @description 给用户绑定设备
   * @param {string|number} user_id
   * @param {string[]} sn
   */
  userbindDevices(user_id: string | number, sn: string[]) {
    return request<any, any>({
      url: "/admin/user/bindDevice",
      method: "post",
      data: { user_id, sn },
    });
  },

  /**
   * @description 批量编辑设备位置
   * @param {any} data
   */
  updateDevicesPos(data: any) {
    return request<any, any>({
      url: "/admin/user/changeDeviceLocation",
      method: "post",
      data,
    });
  },

  /**
   * 获取设备情况分页列表
   *
   * @param data 查询参数
   */
  getUserWithDevicePage(data: DeviceSituationSearch) {
    return request<any, PageDataModel<UserDeviceModel>>({
      url: "/admin/user/allUserDeviceList",
      method: "post",
      data,
    });
  },

  /**
   * @description 用户设备详情
   * @param {number|string} sn
   */
  userDeviceDetail(sn: number | string) {
    return request<any, UserDeviceModel>({
      url: "/admin/user/userDeviceDetail",
      method: "post",
      data: {
        sn: sn,
      },
    });
  },

  /**
   * @description 根据设备Sn获取设备日志情况
   * @param { UserDeviceLogsSearch } data
   */
  getUserDeviceLogs(data: UserDeviceLogsSearch): Promise<PageDataModel<DeviceLogModel>> {
    return request<any, PageDataModel<DeviceLogModel>>({
      url: "/admin/user/getDeviceLogBySn",
      method: "post",
      data: data,
    });
  },

  /**
   * @description 获取用户家庭的设备日志情况
   * @param { UserHouseDeviceLogsSearch } data
   */
  getDeviceLogByUserId(data: UserHouseDeviceLogsSearch): Promise<PageDataModel<DeviceLogModel>> {
    return request<any, PageDataModel<DeviceLogModel>>({
      url: "/admin/user/getDeviceLogByUserId",
      method: "post",
      data: data,
    });
  },

  /**
   * @description 获取设备的安装位置 坐标
   * @param {string} sn
   */
  getDeviceAddressBySn(sn: string) {
    return request<any, any>({
      url: "/admin/user/getDeviceAddressBySn",
      method: "post",
      data: {
        sn: sn,
      },
    });
  },

  /**
   * @description 设置摔倒报警器安装高度
   * @param {string} sn
   * @param {number|string} height
   */
  setFlInstallHeight(sn: string, height: number | string) {
    return request<any, any>({
      url: "/admin/user/setFlInstallHeight",
      method: "post",
      data: {
        sn: sn,
        height: height,
      },
    });
  },

  /**
   * @description 设置摔倒报警器跌倒时长
   * @param {string} sn
   * @param {number|string} time
   */
  setFlFallDuration(sn: string, time: number | string) {
    return request<any, any>({
      url: "/admin/user/setFlFallDuration",
      method: "post",
      data: {
        sn: sn,
        time: time,
      },
    });
  },

  /**
   * 修改in_house 状态
   */
  changeDeviceHouse(sn: string, in_house: number) {
    return request<any, any>({
      url: "/admin/user/changeDeviceHouse",
      method: "post",
      data: {
        sn: sn,
        in_house: in_house,
      },
    });
  },

  /**
   * 手动解除报警状态
   * @param {string} sn
   */
  removeWaring(sn: string) {
    return request<any, any>({
      url: "/admin/user/removeWaring",
      method: "post",
      data: {
        sn: sn,
      },
    });
  },
};

export default DeviceAPI;
